import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { ToolTipItem } from "../../../../com/mui/manager/ToolTipItem";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { SWedding } from "../../../../Message/Public/SWedding";
import { Cache } from "../../cache/Cache";
import { Global } from "../../../../com/gengine/global/Global";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class MarryWeddingView
    
    export  class MarryWeddingView extends View
    {
        constructor()
        {
            super();
            this.layer = LayerManager.uiLayer;
            this.mouseEnabled = false;
            this.mouseChildren = true;
            this.createChildren();
            this.resetPosition();
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=null;
            this._bmpBg = new Object /* flash.display.Bitmap */();
            this.addChild(this._bmpBg);
            loc1 = new ToolTipItem();
            loc1.graphics.beginFill(16777215, 0.01);
            loc1.graphics.drawRect(0, 0, 85, 80);
            loc1.graphics.endFill();
            loc1.cacheAsBitmap = true;
            loc1.toolTipData = HTMLUtil.addColor(Language.getString(41622), "#FFFFFF");
            ObjCreate.setObjAttri(loc1, 9, 9, -1, -1, this);
            var loc2=new ToolTipItem();
            loc2.graphics.beginFill(16777215, 0.01);
            loc2.graphics.drawRect(0, 0, 85, 80);
            loc2.graphics.endFill();
            loc2.cacheAsBitmap = true;
            loc2.toolTipData = HTMLUtil.addColor(Language.getString(41622), "#FFFFFF");
            ObjCreate.setObjAttri(loc2, 437, 9, -1, -1, this);
            this._bmpOver = new Object /* flash.display.Bitmap */();
            this._bmpOver.x = 92;
            this._bmpOver.y = 65;
            this.addChild(this._bmpOver);
            this._btnStartWedding = ObjCreate.createGButton(Language.getString(43633), 111, 30, 77, 34, this, "WeddingBtn");
            this._btnSendGift = ObjCreate.createGButton(Language.getString(43634), 186, 30, 77, 34, this, "WeddingBtn");
            this._btnLookGift = ObjCreate.createGButton(Language.getString(43635), 186, 30, 77, 34, this, "WeddingBtn");
            this._btnShowShop = ObjCreate.createGButton(Language.getString(43636), 261, 30, 77, 34, this, "WeddingBtn");
            this._btnManageGuest = ObjCreate.createGButton(Language.getString(43637), 336, 30, 77, 34, this, "WeddingBtn");
            this._tfSweet = ObjCreate.createTextField("", 245, 60, 150, 20, this);
            this._toolTipItem = new ToolTipItem();
            this._toolTipItem.graphics.beginFill(16777215, 0.01);
            this._toolTipItem.graphics.drawRect(0, 0, 360, 20);
            this._toolTipItem.graphics.endFill();
            this._toolTipItem.cacheAsBitmap = true;
            ObjCreate.setObjAttri(this._toolTipItem, 92, 61, -1, -1, this);
            this._toolTipItem.toolTipData = Language.getString(43638);
            this.loadRes();
            loc1.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onStartDrag);
            loc2.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onStartDrag);
            loc1.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onEndDrag);
            loc2.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onEndDrag);
            this._btnStartWedding.addEventListener(flash.events.MouseEvent.CLICK, this.onStartWedding);
            this._btnSendGift.addEventListener(flash.events.MouseEvent.CLICK, this.onSendGift);
            this._btnLookGift.addEventListener(flash.events.MouseEvent.CLICK, this.onLookGift);
            this._btnShowShop.addEventListener(flash.events.MouseEvent.CLICK, this.onShowShop);
            this._btnManageGuest.addEventListener(flash.events.MouseEvent.CLICK, this.onManageGuest);
            return;
        }

        /* internal  */onStartDrag(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.startDrag();
            return;
        }

        /* internal  */onEndDrag(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.stopDrag();
            return;
        }

        /* internal  */onStartWedding(arg1: Object /* flash.events.MouseEvent */): void
        {
            Alert.show(Language.getString(43639), null, Alert.OK | Alert.CANCEL, null, this.onStartAlertClose);
            return;
        }

        /* internal  */onStartAlertClose(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.MarryStartWedding));
            }
            return;
        }

        /* internal  */onSendGift(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarryShowBlessWindow, this._wedding));
            return;
        }

        /* internal  */onLookGift(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarryShowBlessWindow, this._wedding));
            return;
        }

        /* internal  */onShowShop(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarryWeddingRequestShopData));
            return;
        }

        /* internal  */onManageGuest(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarryShowManageWindow, this._wedding));
            return;
        }

        /* internal  */loadRes(): void
        {
            LoaderManager.instance.load("SweetProcessOver.png", this.onLoadOverComplete);
            LoaderManager.instance.load("MarryWeddingBg.swf", this.onLoadBgComplete);
            return;
        }

        /* internal  */onLoadOverComplete(arg1: Object): void
        {
            this._bmpdOverConst = arg1.bitmapData as Object /* flash.display.BitmapData */;
            this._isLoadOverData = true;
            this.drawBmp();
            return;
        }

        /* internal  */onLoadBgComplete(arg1: Object): void
        {
            this._bmpBg.bitmapData = arg1.bitmapData as Object /* flash.display.BitmapData */;
            return;
        }

        public updateSweet(arg1: int, arg2: int=3344): void
        {
            this._currentSweet = arg1;
            this._maxSweet = arg2;
            this._tfSweet.text = arg1.toString() + "/" + arg2.toString();
            if (this._isLoadOverData) 
            {
                this.drawBmp();
            }
            return;
        }

        /* internal  */drawBmp(): void
        {
            var loc1=this._currentSweet / this._maxSweet;
            loc1 = loc1 < 0 ? 0 : loc1;
            loc1 = loc1 > 1 ? 1 : loc1;
            var loc2=0;
            this._bmpOver.bitmapData = null;
            if (this._bmpdOver) 
            {
                this._bmpdOver.dispose();
            }
            if (loc1 > 0) 
            {
                loc2 = loc1 * this._bmpdOverConst.width;
                if (loc2 >= 1) 
                {
                    this._bmpdOver = new Object /* flash.display.BitmapData */(loc2, this._bmpdOverConst.height, true, 16777215);
                    this._bmpdOver.draw(this._bmpdOverConst, null, null, null, new Object /* flash.geom.Rectangle */(0, 0, loc2, this._bmpdOverConst.height));
                    this._bmpOver.bitmapData = this._bmpdOver;
                }
            }
            return;
        }

        public updateWeddingMsg(arg1: SWedding, arg2: Boolean=false): void
        {
            this._wedding = arg1;
            if (!this._wedding) 
            {
                return;
            }
            var loc1=arg1.man.entityId.id == Cache.instance.role.entityInfo.entityId.id || arg1.woman.entityId.id == Cache.instance.role.entityInfo.entityId.id;
            if (loc1 && !arg2) 
            {
                this._btnStartWedding.enabled = true;
            }
            else 
            {
                this._btnStartWedding.enabled = false;
            }
            this._btnManageGuest.enabled = loc1;
            this._btnSendGift.visible = !loc1;
            this._btnLookGift.visible = loc1;
            return;
        }

        public resetPosition(): void
        {
            this.x = (Global.stage.stageWidth - 529) / 2;
            this.y = Global.stage.stageHeight - 190;
            return;
        }

        /* internal */ /* var */_wedding: SWedding;

        /* internal */ /* var */_bmpBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpOver: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpdOver: Object /* flash.display.BitmapData */;

        /* internal */ /* var */_btnStartWedding: GButton;

        /* internal */ /* var */_btnSendGift: GButton;

        /* internal */ /* var */_btnLookGift: GButton;

        /* internal */ /* var */_btnShowShop: GButton;

        /* internal */ /* var */_btnManageGuest: GButton;

        /* internal */ /* var */_tfSweet: Object /* flash.text.TextField */;

        /* internal */ /* var */_toolTipItem: ToolTipItem;

        /* internal */ /* var */_bmpdOverConst: Object /* flash.display.BitmapData */;

        /* internal */ /* var */_isLoadOverData: Boolean=false;

        /* internal */ /* var */_currentSweet: int=0;

        /* internal */ /* var */_maxSweet: int=3344;
    }
